// 获取页面元素
const doctorUl = document.getElementById('doctor-ul');
const patientForm = document.getElementById('patient-form');
const appointmentDatetime = document.getElementById('appointment-datetime');
const bookAppointmentButton = document.getElementById('book-appointment');

// 模拟获取医生列表
function getDoctors() {
  // 实际开发中替换为真实API请求，如：
  // fetch('your-doctor-api-url')
  //  .then(response => response.json())
  //  .then(data => {
  //      data.forEach(doctor => {
  //        const li = document.createElement('li');
  //        li.textContent = `${doctor.name} - ${doctor.specialty}`;
  //        doctorUl.appendChild(li);
  //      });
  //    });
  const doctors = [
    { name: "Dr. Smith", specialty: "Cardiology" },
    { name: "Dr. Johnson", specialty: "Pediatrics" }
  ];
  doctors.forEach(doctor => {
    const li = document.createElement('li');
    li.textContent = `${doctor.name} - ${doctor.specialty}`;
    doctorUl.appendChild(li);
  });
}

// 模拟提交患者信息
patientForm.addEventListener('submit', (e) => {
  e.preventDefault();
  const patientName = document.getElementById('patient-name').value;
  const patientEmail = document.getElementById('patient-email').value;
  const patientPhone = document.getElementById('patient-phone').value;
  // 实际开发中替换为真实API请求，如：
  // fetch('your-patient-api-url', {
  //   method: 'POST',
  //   headers: {
  //     'Content-Type': 'application/json'
  //   },
  //   body: JSON.stringify({ name: patientName, email: patientEmail, phone: patientPhone })
  // })
  // .then(response => response.json())
  // .then(data => console.log(data));
  console.log(`患者信息提交成功：姓名 ${patientName}，邮箱 ${patientEmail}，电话 ${patientPhone}`);
});

// 模拟预约功能
bookAppointmentButton.addEventListener('click', () => {
  const selectedDatetime = appointmentDatetime.value;
  // 实际开发中替换为真实API请求，如：
  // fetch('your-booking-api-url', {
  //   method: 'POST',
  //   headers: {
  //     'Content-Type': 'application/json'
  //   },
  //   body: JSON.stringify({ appointmentTime: selectedDatetime })
  // })
  // .then(response => response.json())
  // .then(data => console.log(data));
  console.log(`预约成功，时间为 ${selectedDatetime}`);
});

window.onload = getDoctors;